package com.lollipop.ucenter.web;

import com.github.pagehelper.PageInfo;
import com.lollipop.common.Result;
import com.lollipop.ucenter.rpc.api.UserService;
import com.lollipop.ucenter.rpc.model.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/page")
    public PageInfo<User> findPager(
            @RequestParam("page") int pageNo, @RequestParam("limit") int pageSize) {
        if (log.isDebugEnabled())
            log.debug(">>> params pageNo is {}, pageSize is {}", pageNo, pageSize);
        return userService.findPager(pageNo, pageSize, new User());
    }

    @PostMapping("/save")
    public Result save(User user) {
        if (log.isDebugEnabled())
            log.debug(">>> params User is {}", user);
        userService.saveOrUpdate(user);
        return Result.success("操作成功.");
    }
}
